    clear  

    cd '~/Dropbox/Data and Replication/Selective default risk/AAO_Selective Default Risk'



    % Bond prices and characteristics   

                    % Dates
                    [ndata, text, alldata] = xlsread('_Work/TEMP/COUPONCHANGES_TABLE_INCLOTHERCURRENCY.xlsx');
       
                    Year=cell2mat(alldata(2:end,11));
                    Month=cell2mat(alldata(2:end,10));
                    Day=cell2mat(alldata(2:end,12));
                    
                    t = datetime(Year,Month,Day);
                      
                      
                    t.Format = 'dd-MMM-yyyy';

                    % Maturity 
                    Maturity= datetime('15-Oct-1949','Locale','en_US');
                    Maturity.Format = 'dd-MMM-yyyy';

                    % Prices (converted in Pound already
                    Prices=ndata(:,6:9);

                         

                   	% Coupons

 
                    COUPON=ndata(:,2:5);
                    COUPON=COUPON./100;
                    
                    Period=2;
                    Basis=0;

                    YTM=NaN(size(Prices));

                for r=1:4
                    for i=1:length(ndata)
                      if isnan(Prices(i,r))==0
                        YTM(i,r)= bndyield(Prices(i,r),COUPON(i,r),t(i,1),Maturity,Period,Basis);
                      else
                        YTM(i,r)=NaN;
                      end
                    end
                end


     HEADER={'Year';'YTM_PD_london';'YTM_PD_paris';'YTM_PD_amsterdam';'YTM_PD_zurich'};


     Panel=cell(length(YTM)+1,5);
     Panel(1,:)=HEADER;
     Panel(2:end,1)=cellstr(t);
     Panel(2:end,2:5)=num2cell(YTM);
 

     T = cell2table(Panel(2:end,:),'VariableNames',Panel(1,:));

    % Write the table to a CSV file
    writetable(T,'_Data/Yield to maturity/YTM_allmarkets.csv')



 